<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  
  <title>Linux系列四之内核优化 | Hexo</title>
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  <meta name="description" content="背景　　近期在做消息推送服务的性能测试，想知道单服务能支撑的最大连接数。在测试过程中发现了一些问题，再加上网上的资料都比较零散。为方便以后资料翻阅，在这篇文章中，我根据自己实际遇到的情况做一个简单的整理！
测试难点　　根据自己实际遇到的情况，再加上网上的一些资料，列出几点大家需要注意的地方。实际不可能有那么多真机，所有都是通过客户端测试程序模拟大量终端的连接。　　1. 服务端限制：服务端需要给每个">
<meta property="og:type" content="article">
<meta property="og:title" content="Linux系列四之内核优化">
<meta property="og:url" content="http://yoursite.com/2015/12/01/linux/4.Linux系列之内核优化/index.html">
<meta property="og:site_name" content="Hexo">
<meta property="og:description" content="背景　　近期在做消息推送服务的性能测试，想知道单服务能支撑的最大连接数。在测试过程中发现了一些问题，再加上网上的资料都比较零散。为方便以后资料翻阅，在这篇文章中，我根据自己实际遇到的情况做一个简单的整理！
测试难点　　根据自己实际遇到的情况，再加上网上的一些资料，列出几点大家需要注意的地方。实际不可能有那么多真机，所有都是通过客户端测试程序模拟大量终端的连接。　　1. 服务端限制：服务端需要给每个">
<meta property="og:updated_time" content="2016-01-29T17:47:36.000Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="Linux系列四之内核优化">
<meta name="twitter:description" content="背景　　近期在做消息推送服务的性能测试，想知道单服务能支撑的最大连接数。在测试过程中发现了一些问题，再加上网上的资料都比较零散。为方便以后资料翻阅，在这篇文章中，我根据自己实际遇到的情况做一个简单的整理！
测试难点　　根据自己实际遇到的情况，再加上网上的一些资料，列出几点大家需要注意的地方。实际不可能有那么多真机，所有都是通过客户端测试程序模拟大量终端的连接。　　1. 服务端限制：服务端需要给每个">
  
    <link rel="alternative" href="/atom.xml" title="Hexo" type="application/atom+xml">
  
  
    <link rel="icon" href="/favicon.png">
  
  <link href="//fonts.googleapis.com/css?family=Source+Code+Pro" rel="stylesheet" type="text/css">
  <link rel="stylesheet" href="/css/style.css" type="text/css">
  

</head>
<body>
  <div id="container">
    <div id="wrap">
      <header id="header">
  <div id="banner"></div>
  <div id="header-outer" class="outer">
    <div id="header-title" class="inner">
      <h1 id="logo-wrap">
        <a href="/" id="logo">Hexo</a>
      </h1>
      
    </div>
    <div id="header-inner" class="inner">
      <nav id="main-nav">
        <a id="main-nav-toggle" class="nav-icon"></a>
        
          <a class="main-nav-link" href="/">Home</a>
        
          <a class="main-nav-link" href="/archives">Archives</a>
        
      </nav>
      <nav id="sub-nav">
        
          <a id="nav-rss-link" class="nav-icon" href="/atom.xml" title="RSS Feed"></a>
        
        <a id="nav-search-btn" class="nav-icon" title="Search"></a>
      </nav>
      <div id="search-form-wrap">
        <form action="//google.com/search" method="get" accept-charset="UTF-8" class="search-form"><input type="search" name="q" results="0" class="search-form-input" placeholder="Search"><button type="submit" class="search-form-submit">&#xF002;</button><input type="hidden" name="sitesearch" value="http://yoursite.com"></form>
      </div>
    </div>
  </div>
</header>
      <div class="outer">
        <section id="main"><article id="post-linux/4.Linux系列之内核优化" class="article article-type-post" itemscope itemprop="blogPost">
  <div class="article-meta">
    <a href="/2015/12/01/linux/4.Linux系列之内核优化/" class="article-date">
  <time datetime="2015-11-30T20:00:00.000Z" itemprop="datePublished">2015-12-01</time>
</a>
    
  <div class="article-category">
    <a class="article-category-link" href="/categories/linux/">linux</a>
  </div>

  </div>
  <div class="article-inner">
    
    
      <header class="article-header">
        
  
    <h1 class="article-title" itemprop="name">
      Linux系列四之内核优化
    </h1>
  

      </header>
    
    <div class="article-entry" itemprop="articleBody">
      
        <h2 id="u80CC_u666F"><a href="#u80CC_u666F" class="headerlink" title="背景"></a>背景</h2><p>　　近期在做消息推送服务的性能测试，想知道单服务能支撑的最大连接数。在测试过程中发现了一些问题，再加上网上的资料都比较零散。为方便以后资料翻阅，在这篇文章中，我根据自己实际遇到的情况做一个简单的整理！</p>
<h2 id="u6D4B_u8BD5_u96BE_u70B9"><a href="#u6D4B_u8BD5_u96BE_u70B9" class="headerlink" title="测试难点"></a>测试难点</h2><p>　　根据自己实际遇到的情况，再加上网上的一些资料，列出几点大家需要注意的地方。实际不可能有那么多真机，所有都是通过客户端测试程序模拟大量终端的连接。<br>　　1. <strong>服务端限制</strong>：服务端需要给每个tcp连接分配一个端口，一个客户端ip能够分配的端口范围可以通过 cat /proc/sys/net/ipv4/ip_local_port_range 命令查看，但是多个客户端则可以有相同的端口(通过ip:port区别)。由于端口是16位整数，也就只能是0到 65535，而0到1023是预留端口，所以能分配的只是1024到65534，也就是64511个。也就是说，一台机器只能创建六万多个长连接。要达到百万连接，需要大概18台客户端。如果单个客户端发起连接太多，java应该会抛出异常java.net.NoRouteToHostException。注意：每个客户端连接，都会产生一个连接端口，该端口由服务端确定，给每个客户端。此处修改只在模拟并发时有用，真实上线时效果不大<br>　　2. <strong>客户端数量</strong>：（本人测试时机器足够，无此问题）上面预估了需要的客户端数量，如果不够该怎么办？客户机器绑定多张网卡或者虚拟网卡的基础上，给每个网卡分配一个IP地址，在起socket的时候指定socket client绑定的IP。<br>　　3. <strong>客户端程序</strong>：由于推送服务需要检测心跳信息，确认连接正常，所以测试程序需要发送心跳信息，并要能够连接是否正常。<br>　　4. kill掉服务，可能导致运行客户端的虚拟机不能ssh登陆，通过vnc连接，查看客户端虚拟机CPU，dmesg中存在Out of socket memory这样的错误信息，原因：服务端和客户端之间存在4万连接，服务进程挂掉后客户端机器收到大量FIN包导致网络相关内存溢出，而客户端机器上存在一个使用curl的定时任务，网络内存溢出引发其某个bug，进而引发CPU跑满。因此调大net.ipv4.tcp_mem配置，注意该参数的单位是页，而不是字节（ 本人没遇到过，在此只是记录一下）</p>
<h2 id="u6700_u5927_u6587_u4EF6_u63CF_u8FF0_u7B26"><a href="#u6700_u5927_u6587_u4EF6_u63CF_u8FF0_u7B26" class="headerlink" title="最大文件描述符"></a>最大文件描述符</h2><p>　　客户端连接越来越多时会出现异常：java.net.SocketException: Too many open files，此时需要修改服务器的最大句柄数。注意：open files是针对单一进程的限制，我们可以通过启动多个服务来解决（不建议，无法得到推送服务的性能极限）。最大句柄数不是越大越好，系统限制的最大值为：1048576（在2.6.25内核之前有个 宏定义，定义了这个值的最大值为1024*1024，在2.6.25内核及其之后，这个值是可以通过/proc/sys/fs /nr_open来设置），设置方式如下：<br><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># 查看系统对单进程的open files最大数限制：1048576</span></span><br><span class="line">cat /proc/sys/fs/nr_open</span><br><span class="line"></span><br><span class="line"><span class="comment">#永久修改open files</span></span><br><span class="line">vi /etc/security/limits.conf</span><br><span class="line"><span class="comment"># hard limit不能大于/proc/sys/fs/nr_open</span></span><br><span class="line"><span class="comment">#* hard nofile 1048576  </span></span><br><span class="line"><span class="comment">#* soft nofile 1048576</span></span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="comment">#修改单个文件打开最大句柄数，临时修改open files，重启后失效</span></span><br><span class="line"><span class="comment">#注意不能超过上面的1048576，通过ulimit -a 查看所有参数的说明</span></span><br><span class="line"><span class="comment">#也不能超过/etc/security/limits.conf中的配置</span></span><br><span class="line"><span class="built_in">ulimit</span> -n <span class="number">1048576</span></span><br><span class="line"></span><br><span class="line"><span class="comment">#注意soft limit不能大于hard limit</span></span><br><span class="line"></span><br><span class="line"><span class="comment">#同时设置soft limit和hard limit</span></span><br><span class="line"><span class="built_in">ulimit</span> -n <span class="number">1800000</span></span><br><span class="line"><span class="comment">#设置soft limit，必须小于hard limit</span></span><br><span class="line"><span class="built_in">ulimit</span> -Sn <span class="number">1600000</span></span><br><span class="line"></span><br><span class="line"><span class="comment">#ulimit -n默认查看的是soft limit</span></span><br><span class="line"></span><br><span class="line"><span class="comment">#查看hard limit</span></span><br><span class="line"><span class="built_in">ulimit</span> -Hn</span><br><span class="line"></span><br><span class="line"><span class="comment">#注销用户重新登录，执行ulimit -a 检查修改是否生效</span></span><br><span class="line"><span class="comment">#也可以通过如下命令查看指定进程的最大文件句柄数（需将pid改为实际的进程号）</span></span><br><span class="line">cat /proc/pid/limits</span><br><span class="line"></span><br><span class="line"><span class="comment">#在/etc/sysctl.conf中配置系统所有进程打开的文件数，修改参数fs.file-max即可</span></span><br><span class="line"></span><br><span class="line"><span class="comment">#查看当前系统使用的打开文件描述符数情况</span></span><br><span class="line">cat /proc/sys/fs/file-nr</span><br><span class="line"><span class="number">5664</span>        <span class="number">0</span>        <span class="number">186405</span></span><br><span class="line"><span class="comment">#第一个数表示当前系统已分配使用的打开文件描述符数</span></span><br><span class="line"><span class="comment">#第二个数为分配后已释放的（目前已不再使用）</span></span><br><span class="line"><span class="comment">#第三个数等于file-max。</span></span><br></pre></td></tr></table></figure></p>
<h2 id="u5E38_u7528_u547D_u4EE4"><a href="#u5E38_u7528_u547D_u4EE4" class="headerlink" title="常用命令"></a>常用命令</h2><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">#确认最终建立的tcp连接数，包括estab、closed、timewait等状态的</span></span><br><span class="line"><span class="comment">#-s, --summary        show socket usage summary</span></span><br><span class="line">ss <span class="operator">-s</span></span><br><span class="line"></span><br><span class="line"><span class="comment">#系统日志信息，压力测试时可以看到很多socket相关的信息</span></span><br><span class="line"><span class="comment">#将信息输出到指定的文件中</span></span><br><span class="line">dmesg &gt; /home/log.data</span><br></pre></td></tr></table></figure>
<h2 id="/etc/sysctl-conf"><a href="#/etc/sysctl-conf" class="headerlink" title="/etc/sysctl.conf"></a>/etc/sysctl.conf</h2><p>　　高负载系统，修改配置文件/etc/sysctl.conf 中参数，调整网络参数。然后执行 <strong>/sbin/sysctl -p</strong> 使配置立即生效<br><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br></pre></td><td class="code"><pre><span class="line">net.ipv4.tcp_syncookies = <span class="number">1</span></span><br><span class="line"><span class="comment">#开启SYN Cookies。当出现SYN等待队列溢出时，启用cookies来处理，可防范少量SYN攻击，默认为0，表示关闭</span></span><br><span class="line"></span><br><span class="line">net.ipv4.tcp_rmem = <span class="number">4096</span> <span class="number">4096</span> <span class="number">16777216</span>  </span><br><span class="line"><span class="comment">#配置读缓冲的大小，三个值，第一个是这个读缓冲的最小值，第三个是最大值，中间的是默认值。</span></span><br><span class="line"><span class="comment">#可以在程序中修改读缓冲的大小，但是不能超过最小与最大。</span></span><br><span class="line"></span><br><span class="line">net.ipv4.tcp_wmem = <span class="number">4096</span> <span class="number">4096</span> <span class="number">16777216</span></span><br><span class="line"><span class="comment">#配置写缓冲的大小。</span></span><br><span class="line"><span class="comment">#读缓冲与写缓冲在大小，直接影响到socket在内核中内存的占用。</span></span><br><span class="line"></span><br><span class="line">net.ipv4.tcp_mem = <span class="number">786432</span> <span class="number">2097152</span> <span class="number">3145728</span>  </span><br><span class="line"><span class="comment">#配置tcp的内存大小，其单位是页，而不是字节。</span></span><br><span class="line"><span class="comment">#当超过第二个值时，TCP进入 pressure模式，此时TCP尝试稳定其内存的使用</span></span><br><span class="line"><span class="comment">#当小于第一个值时，就退出pressure模式。</span></span><br><span class="line"><span class="comment">#当内存占用超过第三个值时，TCP就拒绝分配 socket了</span></span><br><span class="line"><span class="comment">#查看dmesg，会打出很多的日志“TCP: too many of orphaned sockets”。</span></span><br><span class="line"></span><br><span class="line">net.ipv4.tcp_max_orphans = <span class="number">131072</span>  </span><br><span class="line"><span class="comment">#孤儿socket最大数量</span></span><br><span class="line"><span class="comment">#系统所能处理不属于任何进程的 socket数量，当需要快速建立大量连接时，就要关注下这个值。</span></span><br><span class="line"><span class="comment">#当不属于任何进程的socket的数量大于这个值时，dmesg就会看 到”too many of orphaned sockets”。</span></span><br><span class="line"></span><br><span class="line">net.ipv4.tcp_tw_reuse = <span class="number">1</span>  </span><br><span class="line"><span class="comment">#开启重用。允许将TIME-WAIT sockets重新用于新的TCP连接，默认为0，表示关闭；</span></span><br><span class="line"></span><br><span class="line">net.ipv4.tcp_tw_recycle = <span class="number">1</span>  </span><br><span class="line"><span class="comment">#开启TCP连接中TIME-WAIT sockets的快速回收，默认为0，表示关闭。</span></span><br><span class="line"></span><br><span class="line">net.ipv4.tcp_max_tw_buckets = <span class="number">5000</span></span><br><span class="line"><span class="comment">#系统同时保持TIME_WAIT套接字的最大数量，如果超过这个数字，TIME_WAIT套接字将立刻被清除并打印警告信息。</span></span><br><span class="line"><span class="comment">#默认为 180000，改为5000。</span></span><br><span class="line"><span class="comment">#对于Apache、Nginx等服务器，上几行的参数可以很好地减少TIME_WAIT套接字数量，</span></span><br><span class="line"><span class="comment">#对于Squid，效果不大。此项参数可以控制TIME_WAIT套接字的最大数量，避免Squid服务器被大量的TIME_WAIT套接字拖死。</span></span><br><span class="line"></span><br><span class="line">net.ipv4.tcp_fin_timeout = <span class="number">30</span>  </span><br><span class="line"><span class="comment">#如果套接字由本端要求关闭，这个参数决定了它保持在FIN-WAIT-2状态的时间。</span></span><br><span class="line"></span><br><span class="line">net.ipv4.tcp_keepalive_time = <span class="number">1200</span>  </span><br><span class="line"><span class="comment">#当keepalive起用的时候，**TCP发送keepalive消息的频度**。缺省是2小时，改为20分钟。</span></span><br><span class="line"></span><br><span class="line">net.ipv4.ip_<span class="built_in">local</span>_port_range = <span class="number">1024</span> <span class="number">65000</span>  </span><br><span class="line"><span class="comment">#用于向外连接的端口范围。缺省情况下很小：32768到61000，改为1024到65000。</span></span><br><span class="line"></span><br><span class="line">net.ipv4.tcp_max_syn_backlog = <span class="number">8192</span>  </span><br><span class="line"><span class="comment">#SYN队列的长度，默认为1024，加大队列长度为8192，可以容纳更多等待连接的网络连接数。</span></span><br><span class="line"></span><br><span class="line">fs.file-max</span><br><span class="line"><span class="comment">#针对整个系统而非单个进程的文件句柄的最大数量（所有进程的总数），文件句柄设置表示在linux系统中可以打开的文件数量。</span></span><br><span class="line"></span><br><span class="line"><span class="comment">#如果高负载系统使用了netfilter/iptables，调整以下参数</span></span><br><span class="line">net.ipv4.ip_conntrack_max = <span class="number">655360</span>  </span><br><span class="line"><span class="comment">#在内核内存中netfilter可以同时处理的“任务”（连接跟踪条目）</span></span><br><span class="line">net.ipv4.netfilter.ip_conntrack_tcp_timeout_established = <span class="number">180</span>  </span><br><span class="line"><span class="comment">#跟踪的连接超时结束时间</span></span><br></pre></td></tr></table></figure></p>
<h2 id="/proc_u865A_u62DF_u6587_u4EF6_u7CFB_u7EDF"><a href="#/proc_u865A_u62DF_u6587_u4EF6_u7CFB_u7EDF" class="headerlink" title="/proc虚拟文件系统"></a>/proc虚拟文件系统</h2><p>　　/proc/sys目录下存放着大多数的内核参数，并且设计成可以<strong>在系统运行的同时进行更改</strong>，不需要重新引导系统, 不过重新启动机器后会失效，可以通过更改/proc/sys中内核参数对应的文件 /etc/sysctl.conf 的内核参数来永久更改。<br>　　下面我们以打开内核的 ip转发功能为例说明在系统运行时修改内核参数的两种方法。IP转发是指允许系统对来源和目的地都不是本机的数据包通过网络，RedHat默认屏蔽此功能，在 需要用本机作为路由器、NAT等情况下需要开启此功能。<br>　　方法一：直接修改内核参数ip_forward对应在/proc下的文件/proc/sys/net/ipv4/ip_forward内容，<br><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">#查看ip_forward文件内容，该文件默认值0是禁止ip转发，1是开启ip转发功能。</span></span><br><span class="line">cat /proc/sys/net/ipv4/ip_forward</span><br><span class="line"><span class="comment">#修改为开启状态，如果系统重启后则又恢复为默认值0</span></span><br><span class="line"><span class="built_in">echo</span> <span class="number">1</span> &gt; /proc/sys/net/ipv4/ip_forward</span><br></pre></td></tr></table></figure></p>
<p>　　方法二．修改/etc/sysctl.conf文件，每次系统启动时初始化脚本/etc/rc.d/rc.sysinit会读取/etc/sysctl.conf文件的内容，所以修改后每次系统启动时都会开启ip转发功能<br><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">#修改/etc/sysctl.conf</span></span><br><span class="line">vi /etc/sysctl.conf</span><br><span class="line"><span class="comment">#将ip_forward值改为1，重启仍然生效</span></span><br><span class="line">net.ipv4.ip_forward = <span class="number">1</span></span><br><span class="line"><span class="comment">#使修改马上生效</span></span><br><span class="line">sysctl –p</span><br></pre></td></tr></table></figure></p>
<p>　　将/proc/sys中的文件转换成 sysctl 中的变量依据下面两个简单的规则：<br>　　1．去掉前面部分/proc/sys<br>　　2．将文件名中的斜杠变为点。</p>
<p>　　这两条规则可以将/proc/sys中的任一文件名转换成sysctl中的变量名。例如：<br>　　/proc/sys/net/ipv4/ip_forward -&gt; net.ipv4.ip_forward<br>　　/proc/sys/kernel/hostname -&gt; kernel.hostname</p>
<p>　　可以使用命令<strong>sysctl –a</strong>查询所有可修改的变量名，下面例举几个简单的内核参数：<br>　　1．/proc/sys/kernel/shmmax 该文件指定内核所允许的最大共享内存段的大小。<br>　　2．/proc/sys/kernel/threads-max 该文件指定内核所能使用的线程的最大数目。<br>　　3．/proc/sys/kernel/hostname 该文件允许您配置网络主机名。<br>　　4．/proc/sys/kernel/domainname 该文件允许您配置网络域名</p>
<h2 id="u603B_u7ED3"><a href="#u603B_u7ED3" class="headerlink" title="总结"></a>总结</h2><p>　　1. 所有进程打开的文件描述符数不能超过/proc/sys/fs/file-max<br>　　2. 单个进程打开的文件描述符数不能超过user limit中nofile的soft limit<br>　　3. nofile的soft limit不能超过其hard limit<br>　　4. nofile的hard limit不能超过/proc/sys/fs/nr_open<br>　　在测试的过程中，需要根据dmesg打出系统的信息不断调整服务端/etc/sysctl.conf中的配置。</p>
<h2 id="u53C2_u8003_u8D44_u6599"><a href="#u53C2_u8003_u8D44_u6599" class="headerlink" title="参考资料"></a>参考资料</h2><p><a href="http://qa.blog.163.com/blog/static/190147002201342115957410/" target="_blank" rel="external">http://qa.blog.163.com/blog/static/190147002201342115957410/</a><br><a href="http://blog.csdn.net/superchanon/article/details/13303705" target="_blank" rel="external">http://blog.csdn.net/superchanon/article/details/13303705</a><br><a href="http://f.dataguru.cn/article-7442-1.html" target="_blank" rel="external">http://f.dataguru.cn/article-7442-1.html</a></p>

      
    </div>
    <footer class="article-footer">
      <a data-url="http://yoursite.com/2015/12/01/linux/4.Linux系列之内核优化/" data-id="cijzzpvcl00bi1cfsuo10twdq" class="article-share-link">Share</a>
      
      
  <ul class="article-tag-list"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/linux/">linux</a></li></ul>

    </footer>
  </div>
  
    
<nav id="article-nav">
  
    <a href="/2015/12/01/rpc/5.RPC系列之Thrift入门/" id="article-nav-newer" class="article-nav-link-wrap">
      <strong class="article-nav-caption">Newer</strong>
      <div class="article-nav-title">
        
          RPC系列五之Thrift入门
        
      </div>
    </a>
  
  
    <a href="/2015/12/01/rpc/4.RPC系列之HttpInvoker源码分析/" id="article-nav-older" class="article-nav-link-wrap">
      <strong class="article-nav-caption">Older</strong>
      <div class="article-nav-title">RPC系列四之HttpInvoker源码分析</div>
    </a>
  
</nav>

  
</article>

</section>
        
          <aside id="sidebar">
  
    
  <div class="widget-wrap">
    <h3 class="widget-title">Categories</h3>
    <div class="widget">
      <ul class="category-list"><li class="category-list-item"><a class="category-list-link" href="/categories/cache/">cache</a><span class="category-list-count">3</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/database/">database</a><span class="category-list-count">13</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/docker/">docker</a><span class="category-list-count">6</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/gis/">gis</a><span class="category-list-count">4</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/git/">git</a><span class="category-list-count">2</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/go/">go</a><span class="category-list-count">1</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/gradle/">gradle</a><span class="category-list-count">1</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/groovy/">groovy</a><span class="category-list-count">1</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/hadoop/">hadoop</a><span class="category-list-count">1</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/java/">java</a><span class="category-list-count">18</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/linux/">linux</a><span class="category-list-count">4</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/log/">log</a><span class="category-list-count">11</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/mongodb/">mongodb</a><span class="category-list-count">14</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/mq/">mq</a><span class="category-list-count">6</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/mybatis/">mybatis</a><span class="category-list-count">9</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/netty/">netty</a><span class="category-list-count">1</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/nginx/">nginx</a><span class="category-list-count">3</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/nio/">nio</a><span class="category-list-count">19</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/nodejs/">nodejs</a><span class="category-list-count">1</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/redis/">redis</a><span class="category-list-count">6</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/rpc/">rpc</a><span class="category-list-count">14</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/spring/">spring</a><span class="category-list-count">5</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/tomcat/">tomcat</a><span class="category-list-count">2</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/zookeeper/">zookeeper</a><span class="category-list-count">2</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/杂项/">杂项</a><span class="category-list-count">2</span></li></ul>
    </div>
  </div>

  
    
  <div class="widget-wrap">
    <h3 class="widget-title">Tags</h3>
    <div class="widget">
      <ul class="tag-list"><li class="tag-list-item"><a class="tag-list-link" href="/tags/aop/">aop</a><span class="tag-list-count">8</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/aspectj/">aspectj</a><span class="tag-list-count">3</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/cache/">cache</a><span class="tag-list-count">3</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/classloader/">classloader</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/common-loggings/">common-loggings</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/commonjs/">commonjs</a><span class="tag-list-count">4</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/database/">database</a><span class="tag-list-count">10</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/docker/">docker</a><span class="tag-list-count">6</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/dubbo/">dubbo</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/fastdfs/">fastdfs</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/gclib/">gclib</a><span class="tag-list-count">2</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/geohash/">geohash</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/gis/">gis</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/git/">git</a><span class="tag-list-count">2</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/go/">go</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/gradle/">gradle</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/groovy/">groovy</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/hadoop/">hadoop</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/hessisan/">hessisan</a><span class="tag-list-count">3</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/java/">java</a><span class="tag-list-count">48</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/javassist/">javassist</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/kafka/">kafka</a><span class="tag-list-count">3</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/linux/">linux</a><span class="tag-list-count">4</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/log/">log</a><span class="tag-list-count">11</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/log4j/">log4j</a><span class="tag-list-count">4</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/logback/">logback</a><span class="tag-list-count">5</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/map/">map</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/memecached/">memecached</a><span class="tag-list-count">2</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/mina/">mina</a><span class="tag-list-count">5</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/mongodb/">mongodb</a><span class="tag-list-count">14</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/mq/">mq</a><span class="tag-list-count">6</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/mqtt/">mqtt</a><span class="tag-list-count">2</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/mybatis/">mybatis</a><span class="tag-list-count">9</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/netty/">netty</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/nginx/">nginx</a><span class="tag-list-count">3</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/nio/">nio</a><span class="tag-list-count">5</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/nodejs/">nodejs</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/postgresql/">postgresql</a><span class="tag-list-count">2</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/protobuf/">protobuf</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/proxy/">proxy</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/push/">push</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/rabbitmq/">rabbitmq</a><span class="tag-list-count">3</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/redis/">redis</a><span class="tag-list-count">6</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/rpc/">rpc</a><span class="tag-list-count">14</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/sitemesh/">sitemesh</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/sld/">sld</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/slf4j/">slf4j</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/socket/">socket</a><span class="tag-list-count">7</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/spatialite-for-android/">spatialite for android</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/spi/">spi</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/spring/">spring</a><span class="tag-list-count">13</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/tomcat/">tomcat</a><span class="tag-list-count">2</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/transaction/">transaction</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/web/">web</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/xSocket/">xSocket</a><span class="tag-list-count">7</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/zbus/">zbus</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/zookeeper/">zookeeper</a><span class="tag-list-count">2</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/数据结构/">数据结构</a><span class="tag-list-count">2</span></li></ul>
    </div>
  </div>

  
    
  <div class="widget-wrap">
    <h3 class="widget-title">Tag Cloud</h3>
    <div class="widget tagcloud">
      <a href="/tags/aop/" style="font-size: 15.38px;">aop</a> <a href="/tags/aspectj/" style="font-size: 11.54px;">aspectj</a> <a href="/tags/cache/" style="font-size: 11.54px;">cache</a> <a href="/tags/classloader/" style="font-size: 10px;">classloader</a> <a href="/tags/common-loggings/" style="font-size: 10px;">common-loggings</a> <a href="/tags/commonjs/" style="font-size: 12.31px;">commonjs</a> <a href="/tags/database/" style="font-size: 16.92px;">database</a> <a href="/tags/docker/" style="font-size: 13.85px;">docker</a> <a href="/tags/dubbo/" style="font-size: 10px;">dubbo</a> <a href="/tags/fastdfs/" style="font-size: 10px;">fastdfs</a> <a href="/tags/gclib/" style="font-size: 10.77px;">gclib</a> <a href="/tags/geohash/" style="font-size: 10px;">geohash</a> <a href="/tags/gis/" style="font-size: 10px;">gis</a> <a href="/tags/git/" style="font-size: 10.77px;">git</a> <a href="/tags/go/" style="font-size: 10px;">go</a> <a href="/tags/gradle/" style="font-size: 10px;">gradle</a> <a href="/tags/groovy/" style="font-size: 10px;">groovy</a> <a href="/tags/hadoop/" style="font-size: 10px;">hadoop</a> <a href="/tags/hessisan/" style="font-size: 11.54px;">hessisan</a> <a href="/tags/java/" style="font-size: 20px;">java</a> <a href="/tags/javassist/" style="font-size: 10px;">javassist</a> <a href="/tags/kafka/" style="font-size: 11.54px;">kafka</a> <a href="/tags/linux/" style="font-size: 12.31px;">linux</a> <a href="/tags/log/" style="font-size: 17.69px;">log</a> <a href="/tags/log4j/" style="font-size: 12.31px;">log4j</a> <a href="/tags/logback/" style="font-size: 13.08px;">logback</a> <a href="/tags/map/" style="font-size: 10px;">map</a> <a href="/tags/memecached/" style="font-size: 10.77px;">memecached</a> <a href="/tags/mina/" style="font-size: 13.08px;">mina</a> <a href="/tags/mongodb/" style="font-size: 19.23px;">mongodb</a> <a href="/tags/mq/" style="font-size: 13.85px;">mq</a> <a href="/tags/mqtt/" style="font-size: 10.77px;">mqtt</a> <a href="/tags/mybatis/" style="font-size: 16.15px;">mybatis</a> <a href="/tags/netty/" style="font-size: 10px;">netty</a> <a href="/tags/nginx/" style="font-size: 11.54px;">nginx</a> <a href="/tags/nio/" style="font-size: 13.08px;">nio</a> <a href="/tags/nodejs/" style="font-size: 10px;">nodejs</a> <a href="/tags/postgresql/" style="font-size: 10.77px;">postgresql</a> <a href="/tags/protobuf/" style="font-size: 10px;">protobuf</a> <a href="/tags/proxy/" style="font-size: 10px;">proxy</a> <a href="/tags/push/" style="font-size: 10px;">push</a> <a href="/tags/rabbitmq/" style="font-size: 11.54px;">rabbitmq</a> <a href="/tags/redis/" style="font-size: 13.85px;">redis</a> <a href="/tags/rpc/" style="font-size: 19.23px;">rpc</a> <a href="/tags/sitemesh/" style="font-size: 10px;">sitemesh</a> <a href="/tags/sld/" style="font-size: 10px;">sld</a> <a href="/tags/slf4j/" style="font-size: 10px;">slf4j</a> <a href="/tags/socket/" style="font-size: 14.62px;">socket</a> <a href="/tags/spatialite-for-android/" style="font-size: 10px;">spatialite for android</a> <a href="/tags/spi/" style="font-size: 10px;">spi</a> <a href="/tags/spring/" style="font-size: 18.46px;">spring</a> <a href="/tags/tomcat/" style="font-size: 10.77px;">tomcat</a> <a href="/tags/transaction/" style="font-size: 10px;">transaction</a> <a href="/tags/web/" style="font-size: 10px;">web</a> <a href="/tags/xSocket/" style="font-size: 14.62px;">xSocket</a> <a href="/tags/zbus/" style="font-size: 10px;">zbus</a> <a href="/tags/zookeeper/" style="font-size: 10.77px;">zookeeper</a> <a href="/tags/数据结构/" style="font-size: 10.77px;">数据结构</a>
    </div>
  </div>

  
    
  <div class="widget-wrap">
    <h3 class="widget-title">Archives</h3>
    <div class="widget">
      <ul class="archive-list"><li class="archive-list-item"><a class="archive-list-link" href="/archives/2016/01/">January 2016</a><span class="archive-list-count">67</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2015/12/">December 2015</a><span class="archive-list-count">81</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2015/11/">November 2015</a><span class="archive-list-count">2</span></li></ul>
    </div>
  </div>

  
    
  <div class="widget-wrap">
    <h3 class="widget-title">Recents</h3>
    <div class="widget">
      <ul>
        
          <li>
            <a href="/2016/01/30/资料/">(no title)</a>
          </li>
        
          <li>
            <a href="/2016/01/30/java/13.Classloader系列一/">ClassLoader系列一</a>
          </li>
        
          <li>
            <a href="/2016/01/29/hadoop/1.hadoop系列之源码编译/">hadoop系列一之源码编译</a>
          </li>
        
          <li>
            <a href="/2016/01/29/go/1.GO系列之入门/">Go系列一之入门</a>
          </li>
        
          <li>
            <a href="/2016/01/28/tomcat/2.tomcat性能优化/">tomcat性能优化</a>
          </li>
        
      </ul>
    </div>
  </div>

  
</aside>
        
      </div>
      <footer id="footer">
  
  <div class="outer">
    <div id="footer-info" class="inner">
      &copy; 2016 John Doe<br>
      Powered by <a href="http://hexo.io/" target="_blank">Hexo</a>
    </div>
  </div>
</footer>
    </div>
    <nav id="mobile-nav">
  
    <a href="/" class="mobile-nav-link">Home</a>
  
    <a href="/archives" class="mobile-nav-link">Archives</a>
  
</nav>
    


<script src="http://libs.baidu.com/jquery/2.0.3/jquery.min.js"></script>


  <link rel="stylesheet" href="/fancybox/jquery.fancybox.css" type="text/css">
  <script src="/fancybox/jquery.fancybox.pack.js" type="text/javascript"></script>


<script src="/js/script.js" type="text/javascript"></script>

  </div>
</body>
</html>